﻿using blackhouse.BlackApart.Business.Prices;
using blackhouse.BlackApart.Business.Reservations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace blackhouse.BlackApart.Business.Discounts {
    public class DiscountLastMinute : IDiscount {

        #region Fields

        private IPriceDataAccess dataAccess = Factory.Instance().getp
        
        #endregion

        public void Apply(Variant variant, DateTime arrivalDate, DateTime departureDate, int peoples) {
            if (DateTime.Now + this.timeForLastMinuteApply >= arrivalDate) {
                IPriceRabat lastMinuteRabat = Factory.Instance().GetPriceRabat("lastminute", variant.GetGroups().First().Id);
                if (lastMinuteRabat != null) {
                    variant.Price.ApplyPriceRabat(lastMinuteRabat);
                }
            }
        }

        public void SetXmlConfiguration(XmlElement configurationNode) {
            XmlNodeList xl = configurationNode.GetElementsByTagName("Time");
            if (xl.Count == 1) {
                TimeSpan pts = this.timeForLastMinuteApply;
                if (!TimeSpan.TryParse(xl[0].InnerText.Trim(), out this.timeForLastMinuteApply))
                    this.timeForLastMinuteApply = pts;
            }
        }
    }
}
